package com.dlyk.service.impl;

import com.dlyk.constant.Constants;
import com.dlyk.mapper.TDicTypeMapper;
import com.dlyk.model.TDicType;
import com.dlyk.model.TProduct;
import com.dlyk.query.BaseQuery;
import com.dlyk.query.DicTypeQuery;
import com.dlyk.service.DicTypeService;
import com.dlyk.util.JWTUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: ajie
 * @date: 2024/7/26 19:23:44
 * @version: 1.0
 */
@Service
public class DicTypeServiceImpl implements DicTypeService {

    @Resource
    private TDicTypeMapper tDicTypeMapper;

    @Override
    public List<TDicType> loadAllDicData() {
        return tDicTypeMapper.selectByAll();
    }

    @Override
    public PageInfo<TDicType> getDicTypeByPage(Integer current) {
        //设置PageHelper的分页参数
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        //查询
        List<TDicType> list = tDicTypeMapper.selectDicTypeByPage(BaseQuery.builder().build());
        //封装分页参数到PageInfo
        PageInfo<TDicType> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public TDicType getDicTypeById(Integer id) {
        return tDicTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int saveDicType(DicTypeQuery dicTypeQuery) {

        TDicType tDicType = new TDicType();

        BeanUtils.copyProperties(dicTypeQuery,tDicType);

        return tDicTypeMapper.insertSelective(tDicType);
    }

    @Override
    public int updateDicType(DicTypeQuery dicTypeQuery) {

        TDicType tDicType = new TDicType();

        BeanUtils.copyProperties(dicTypeQuery,tDicType);

        return tDicTypeMapper.updateByPrimaryKeySelective(tDicType);
    }

    @Override
    public int delDicTypeById(Integer id) {
        return tDicTypeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int batchDelDicTypeByIds(List<String> idList) {
        return tDicTypeMapper.deleteByIds(idList);
    }
}
